var selected_data_ids = new Array();
var delete_ids = new Array();
$(function() {
	var updateAutoId = $.cookie('updateAutoId');
	loadSummById(updateAutoId);
	initEnvAndUrl();
	initTable();
	delete_ids = [];
	$(window).bind(
			"scroll",
			function() {
				var sTop = $(window).scrollTop();
				var sTop = parseInt(sTop);
				if ($("#interparamsTbody").length > 0) {
					var paramsdivlen = $("#interparamsTbody").offset().top;
					var functiondivlen = $("#funcselectionDiv").offset().top
							- $("#selectParamsDiv").height();
					if (sTop >= paramsdivlen && sTop < functiondivlen) {
						if (!$("#selectIconDiv").is(":visible")) {
							try {
								$("#selectIconDiv").slideDown();
							} catch (e) {
								$("#selectIconDiv").show();
							}
						}
						if ($("#selectFunctionDiv").is(":visible")) {
							try {
								$("#selectFunctionDiv").slideUp();
							} catch (e) {
								$("#selectFunctionDiv").hide();
							}
						}
					} else if (sTop >= functiondivlen) {
						if (!$("#selectFunctionDiv").is(":visible")) {
							try {
								$("#selectFunctionDiv").slideDown();
							} catch (e) {
								$("#selectFunctionDiv").show();
							}
						}
					} else {
						if ($("#selectIconDiv").is(":visible")) {
							try {
								$("#selectIconDiv").slideUp();
							} catch (e) {
								$("#selectIconDiv").hide();
							}
						}
					}
				}
			});
});

$(document).ready(function(){});

function initEnvAndUrl(id) {
	$.ajax({
		url : "/smarttest-frontstage/autog7/getTestUrlData.action",
		data : {},
		method : 'POST',
		async : false,
		error : function(response, error) {
			dialog('error', 'error' + response.status, 3000);
		},
		success : function(data) {
			if (data.status == 200 && data.data) {
				var html = "";
				for (var i = 0; i < data.data.length; i++) {
					var value = data.data[i];
					var defined = "";
					if (value.id == id) {
						defined = "defined=\"self\"";
					}
					html += "<option value=\"" + value.id + "\" " + defined
							+ ">" + value.name + "</option>";
				}
				$("#environment").html("");
				$("#environment").html(html);
				code = 0;
			}
		}
	});
	var env = document.getElementById("environment");
	showURL(env);
	showModules(env);
}
function initTable() {
	$("#checkAll").click(function() {
		if (this.checked == true) {
			selected_data_ids = [];
			$(".checkTestData").each(function() {
				this.checked = true;
				var pulled = $(this).parent().parent();
				selected_data_ids.push(pulled);
			});
		} else {
			$(".checkTestData").each(function() {
				this.checked = false;
			});
			selected_data_ids = [];
		}
	});
}

function initInfSelectBox(name) {
	var code = -1;
	var html = "<option value=\"\" selected=\"selected\">-请选择-</option><option value=\"\" onclick=\"$('#myModal').modal();\">-添加-</option>";
	$.ajax({
		url : "/smarttest-frontstage/openapi/searchInfs.action",
		data : {
			searchValue : ''
		},
		method : 'POST',
		async : false,
		success : function(data) {
			if (data.status == 200 && data.data) {
				for (var i = 0; i < data.data.length; i++) {
					var value = data.data[i];
					var defined = "";
					if (value.name == name) {
						defined = "defined=\"self\"";
					}
					html += "<option value=\"" + value.id + "\" " + defined
							+ ">" + value.name + "</option>";
				}
				code = 0;
			}
		}
	});
	$("#interface").empty();
	$("#interface").html(html);
	$("#interface").val(name);
	$("#interface option[defined='self']").filter(function() {
		return $(this).text() == name;
	}).attr('selected', 'selected');
	$('#interface').trigger("change");
	return code;
}
function getParams1(element) {
	var e = $(element);
	var id = e.val();
	if (isStrEmpt(id)) {
		$("#params").html("");
		$("#selectParamsDiv").html("");
	} else {
		var defined = String(e.find("option:selected").attr("defined"));
		var intername = e.find("option:selected").text();
		$
				.ajax({
					url : "/smarttest-frontstage/openapi/searchInfDetail.action",
					data : {
						cid : id,
						defined : defined
					},
					method : 'POST',
					success : function(data) {
						if (data.status == 200 && data.data) {
							for (var i = 0; i < data.data.length; i++) {
								var value = data.data[i];
								if (value && value.param) {
									testJson = eval("(" + value.param + ")");
									var selectParamsDiv = "";
									var paramsdetails = "<table class=\"table table-striped table-bordered table-hover has-tickbox\" style=\"table-layout:fixed\">"
											+ "<thead><tr><th style=\"width:30%;text-align: center;\">参数名</th><th style=\"width:10%;text-align: center;\">必选</th><th style=\"width:10%;text-align: center;\">类型</th><th style=\"width:50%;text-align: center;\">说明</th></tr></thead>"
											+ "<tbody id=\"interparamsTbody\">"
									for (var j = 0; j < testJson.length; j++) {
										var item = testJson[j];
										paramsdetails += "<tr>"
										paramsdetails += "<td style=\"\"><a id=\""
												+ item.name
												+ "\" dragtype=\"interparam\" class=\"btn btn-success\"  type=\"button\" draggable=\"true\" ondragstart=\"drag(event)\">"
												+ item.name + "</a></td>"
										paramsdetails += "<td style=\"\">"
												+ item.required + "</td>"
										paramsdetails += "<td style=\"\">"
												+ item.type + "</td>"
										paramsdetails += "<td style=\"\">"
												+ item.detail + "</td>"
										paramsdetails += "</tr>";
										selectParamsDiv += "<a id=\""
												+ item.name
												+ "\" dragtype=\"interparam\" class=\"btn btn-success\"  type=\"button\" draggable=\"true\" ondragstart=\"drag(event)\">"
												+ item.name + "</a>";
									}
									paramsdetails += "</tbody></table>";
									$("#params").html(paramsdetails);
									$("#method_value input").val(intername);
									$("#selectParamsDiv").html(selectParamsDiv);
								}
							}
						}
					}
				});
	}
}

function getUrlParams() {
	var keys = $('.urlparam_key');
	var values = $('.urlparam_value');
	var JsonUrlParams = "{";
	for (var i = 0; i < keys.length; i++) {
		if (JsonUrlParams != "{") {
			JsonUrlParams += ",";
		}
		JsonUrlParams += "\"" + keys.eq(i).val() + "\":\"" + values.eq(i).val()
				+ "\"";
	}
	JsonUrlParams += "}";
	return JsonUrlParams;
}
function getCurrentCase(element) {
	var input_checked = $(element);
	// var jsonarray_data = "[";
	var datamap = new Map();
	for (var i = 0; i < input_checked.length; i++) {
		var tr = input_checked.eq(i).parent().parent();
		var cases = input_checked.eq(i).parent().parent().children('td');
		var rmp = cases.eq(1).find('tr');
		var testdata = "{";
		if (rmp.length > 0) {
			for (var j = 0; j < rmp.length; j++) {
				if (testdata != "{") {
					testdata += ",";
				}
				var rmptd = rmp.eq(j).find('td');
				testdata += "\"" + rmptd.eq(0).text() + "\":\""
						+ rmptd.eq(2).children().val() + "\"";
			}
		}
		testdata += "}";
		var code = cases.eq(2).children().val();
		var msg = cases.eq(3).children().val();
		var asserts = cases.eq(4).find('label').find('div:first a');
		var assertstr = "{";
		if (asserts.length > 0) {
			for (var j = 0; j < asserts.length; j++) {
				if (assertstr != "{") {
					assertstr += ",";
				}
				var classname = "";
				if (asserts.eq(j).attr('classname') != undefined
						&& asserts.eq(j).attr('classname') != 'undefined') {
					classname = asserts.eq(j).attr('classname');
				}
				assertstr += "\"k" + (j + 1) + "\":\"" + classname + "."
						+ asserts.eq(j).text() + "\"";
			}

		}
		assertstr += "}";
		var expectnum = cases.eq(5).children().val();
		var level = cases.eq(6).find("option:selected").val();
		var details = cases.eq(7).children().val();
		var jsonObject_data = "{\"testdata\":" + testdata
				+ ",\"expectcode\":\"" + code + "\",\"expectmessage\":\"" + msg
				+ "\",\"assertresult\":" + assertstr + ",\"expectnum\":\""
				+ expectnum + "\",\"testlevel\":\"" + level
				+ "\",\"testdetails\":\"" + details + "\"}";
		// if (jsonarray_data != "[") {
		// jsonarray_data+=",";
		// }
		// jsonarray_data+=jsonObject_data;
		datamap.set(tr, jsonObject_data);

	}
	// jsonarray_data+="]";
	// return jsonarray_data;
	return datamap;
}
function getCases() {
	var input_checked = $("#tbody").find('tr').find('td:first input:checked');
	// var jsonarray_data = "[";
	var datamap = new Map();
	for (var i = 0; i < input_checked.length; i++) {
		var tr = input_checked.eq(i).parent().parent();
		var cases = input_checked.eq(i).parent().parent().children('td');
		var rmp = cases.eq(1).find('tr');
		var testdata = "{";
		if (rmp.length > 0) {
			for (var j = 0; j < rmp.length; j++) {
				if (testdata != "{") {
					testdata += ",";
				}
				var rmptd = rmp.eq(j).find('td');
				testdata += "\"" + rmptd.eq(0).text() + "\":\""
						+ rmptd.eq(2).children().val() + "\"";
			}
		}
		testdata += "}";
		var code = cases.eq(2).children().val();
		var msg = cases.eq(3).children().val();
		var asserts = cases.eq(4).find('label').find('div:first a');
		var assertstr = "{";
		if (asserts.length > 0) {
			for (var j = 0; j < asserts.length; j++) {
				if (assertstr != "{") {
					assertstr += ",";
				}
				var classname = "";
				if (asserts.eq(j).attr('classname') != undefined
						&& asserts.eq(j).attr('classname') != 'undefined') {
					classname = asserts.eq(j).attr('classname');
				}
				assertstr += "\"k" + (j + 1) + "\":\"" + classname + "."
						+ asserts.eq(j).text() + "\"";
			}

		}
		assertstr += "}";
		var expectnum = cases.eq(5).children().val();
		var level = cases.eq(6).find("option:selected").val();
		var details = cases.eq(7).children().val();
		var jsonObject_data = "{\"testdata\":" + testdata
				+ ",\"expectcode\":\"" + code + "\",\"expectmessage\":\"" + msg
				+ "\",\"assertresult\":" + assertstr + ",\"expectnum\":\""
				+ expectnum + "\",\"testlevel\":\"" + level
				+ "\",\"testdetails\":\"" + details + "\"}";
		// if (jsonarray_data != "[") {
		// jsonarray_data+=",";
		// }
		// jsonarray_data+=jsonObject_data;
		datamap.set(tr, jsonObject_data);

	}
	// jsonarray_data+="]";
	// return jsonarray_data;
	return datamap;
}
function deleteInterparam(element) {
	var e = $(element).parent().parent();
	e.remove();
	return false;
}

function singleCheckData(checkbox) {
	if (checkbox.checked) {
		var val = $(checkbox).parent().parent();
		if (-1 == $.inArray(val, selected_data_ids)) {
			selected_data_ids.push(val);
		}
	} else {
		var val = $(checkbox).parent().parent();
		var i = $.inArray(val, selected_data_ids);
		if (i > -1) {
			selected_data_ids.splice(i, 1);
		}
	}
}

function deleteInterfacedetails() {
	for (var i = 0; i < selected_data_ids.length; i++) {
		var deleteDatas = $(selected_data_ids[i]);
		var tds = $("> td", deleteDatas);
		var id = $("input", tds[0]).val();
		if (id != "on" && id > 0) {
			delete_ids.push(id);
		}
		deleteDatas.remove();
	}
}

function saveCase() {
	beforeSave();
}

function beforeSave() {
	// id
	var id = $("#sumidHide").val();
	// deleteids
	var deleteidsStr = '';
	for (var i = 0; i < delete_ids.length; i++) {
	    var ideach = delete_ids[i];
	    deleteidsStr = (deleteidsStr + ideach)
		+ (((i + 1) == delete_ids.length) ? '' : ',');
	}
	// 接口
	var inf = $("#interface").find("option:selected").text();
	// 环境
	var env = $("#environment").val();
	// URL
	var url = $("#URL").attr("urlid");
	// 接口类型
	var inftype = $("#intertype").val();
	// 重要程度
	var degree = $("#degree").val();
	// 业务模块
	var module = $("#module").val();
	// 负责人
	var tester = $("#tester").val();
	// 请求方式
	var reqType = $("#requestType").val();
	// outerParam
	var outerparams = getUrlParams();

	var dataAsUrlparam = $("#dataAsUrlparam").attr("checked") == "checked" ? true
			: false;
	// 每项数据
	var trs = $("#tbody > tr");
	var data_items = new Array();
	trs.each(function() {
		var tds = $("> td", this);
		if (tds) {
			var dataItem = new Object();
			var id = $("input", tds[0]).val();
			if (id == "on" || id < 0) {
				id = -1;
			}
			dataItem.id = id;
			dataItem.expectcode = $("input", tds[2]).val();
			dataItem.expectmsg = $("input", tds[3]).val();
			dataItem.expectcount = $("input", tds[5]).val();
			dataItem.level = $("option:selected", tds[6]).val();
			dataItem.description = $("input", tds[7]).val();
			var params_item = $("tr", tds[1]);
			var asserts_item = $(tds[4]).find(
					"a[class*='btn btn-info assert-details']");
			if (params_item.length > 0) {
				var innerparames = solveParam(params_item);
				dataItem.innerparams = innerparames;
			} else {
				// 验证param
			}
			if (asserts_item.length > 0) {
				var resultasserts = solveAssert(asserts_item);
				dataItem.resultasserts = resultasserts;
			} else {
				// 验证断言
			}
			data_items.push(dataItem);
		}
	});
	if (data_items.length > 0) {
		var str = JSON.stringify(data_items);
		$.ajax({
			url : "/smarttest-frontstage/AutoInterface/updateAutoCase.action",
			data : {
				id : id,
				inf : inf,
				env : env,
				url : url,
				inftype : inftype,
				degree : degree,
				module : module,
				tester : tester,
				reqType : reqType,
				outerparams : outerparams,
				dataAsUrlparam : dataAsUrlparam,
				dataitems : str,
				deleteidsStr : deleteidsStr
			},
			method : 'POST',
			success : function(data) {
				if (data.status == 200) {
					dialog('succ', '修改接口自动化用例成功', 3000);
					setTimeout(window.location.href = "autog7.html", 3000);
				}
			}
		});
	} else {
		dialog('error', '修改自动化用例失败：请确定修改条数', 3000);
	}
}

var dataItem = {
	innerparams : "",
	expectcode : "",
	expectmsg : "",
	resultasserts : "",
	expectcount : 1,
	level : 1,
	description : ""
}

function deleteparam1(element) {
	var e = $(element).parent().parent();
	e.remove();
	return false;
}

function solveParam(params) {
	var testdata = "{";
	if (params.length > 0) {
		for (var j = 0; j < params.length; j++) {
			if (testdata != "{") {
				testdata += ",";
			}
			var key = $("a", params[j]).text();
			var val = $("input", params[j]).val();
			testdata += "\"" + key + "\":\"" + val + "\"";
		}
	}
	testdata += "}";
	return testdata;
}

function solveAssert(asserts) {
	var assertstr = "{";
	if (asserts.length > 0) {
		for (var j = 0; j < asserts.length; j++) {
			if (assertstr != "{") {
				assertstr += ",";
			}
			var classname = $(asserts[j]).attr('classname');
			if (classname == undefined || classname == 'undefined') {
				return;
			}
			var val = $(asserts[j]).text();
			assertstr += "\"k" + (j + 1) + "\":\"" + classname + "." + val
					+ "\"";
		}
	}
	assertstr += "}";
	return assertstr;
}

function showURL(element) {
	var env = $(element).find('option:selected').val();
	if (env == 1) {
		$("#URL").val("http://test.tx.router.huoyunren.com/router");
		$("#URL").attr("disabled", "disabled");
		$("#URL").attr("urlid", 1);
	} else if (env == 2) {
		$("#URL").val("http://demo.tx.router.huoyunren.com/router");
		$("#URL").attr("disabled", "disabled");
		$("#URL").attr("urlid", 2);
	} else if (env == 3) {
		$("#URL").val("http://tx.router.huoyunren.com/router");
		$("#URL").attr("disabled", "disabled");
		$("#URL").attr("urlid", 3);
	} else {
		$("#URL").val("");
		$("#URL").removeAttr("disabled");
		$("#URL").attr("urlid", 0);
	}
}
function debugTest(cases) {
	var apiurl = $("#URL").val();
	var method = $("#requestType").find("option:selected").val();
	var outerparams = getUrlParams();
	var isdataAsUrlparam = $("#dataAsUrlparam").prop('checked');
	var intertype = $("#intertype").find('option:selected').val();
	var casesmap = cases;
	if (isStrEmpt(apiurl)) {
		dialog('error', "URL地址不能为空", 3000);
	} else {
		if (intertype == "DSP") {
			if (isStrEmpt($("#app_key").val())) {
				dialog('notice', "请输入APP_KEY", 3000);
				return;
			} else if (isStrEmpt($("#secret").val())) {
				dialog('notice', "请输入SECRET", 3000);
				return;
			} else {
				$("#param_appkey").val($("#app_key").val());
				var signstr = "sign2(appkey,method,format,timestamp,${jsonParams},"
						+ $("#secret").val() + ")";
				$("#param_sign").val(signstr);
			}
		}
		casesmap
				.forEach(function(value, key, map) {
					key
							.find("td:last")
							.html(
									"<img width=\"100%\" height=\"100%\" border=\"0\" src=\"img/msgbox_loading.gif\">");
					$
							.ajax({
								url : "/smarttest-frontstage/autog7/debugTest.action",
								data : {
									apiurl : apiurl,
									httpmethod : method,
									outerparams : outerparams,
									dataAsParams : isdataAsUrlparam,
									cases : value
								},
								method : 'POST',
								error : function(response, error) {
									dialog('error', 'error' + response.status,
											3000);
								},
								success : function(data) {
									if (data.data.result == "PASS") {
										key
												.find("td:last")
												.html(
														"<font color=\"green\">PASS</font>"
																+ "<a class=\"table-expandable-arrow btn btn-sm\" onclick=\"launchTestResult(this);\" style=\"margin:0 auto;margin-top: 5px;\"></a>");
										if (isContains(
												key.next().attr('class'),
												'tr-expandable')) {
											key.next().remove();
										}
										key
												.after("<tr style=\"display: none;overflow: hidden;\" class=\"tr-expandable\"><td colspan=\"10\"> <p><font size=\"2\">接口返回&nbsp;&nbsp;:&nbsp;&nbsp;</font>"
														+ data.data.returns
														+ "</p></td></tr>");
										launchTestResult(key.find("td:last a")
												.get(0));
									} else if (data.data.result == "FAIL") {
										key
												.find("td:last")
												.html(
														"<font color=\"red\">FAIL</font>"
																+ "<a class=\"table-expandable-arrow btn btn-sm\" onclick=\"launchTestResult(this);\" style=\"margin:0 auto;margin-top: 5px;\"></a>");
										if (isContains(
												key.next().attr('class'),
												'tr-expandable')) {
											key.next().remove();
										}
										key
												.after("<tr style=\"display: none;overflow: hidden;\" class=\"tr-expandable\"><td colspan=\"10\"> <p><font size=\"2\">接口返回&nbsp;&nbsp;:&nbsp;&nbsp;</font>"
														+ data.data.returns
														+ "</p><p><font size=\"2\">错误详情&nbsp;&nbsp;:&nbsp;&nbsp;</font><font color=\"red\">"
														+ data.data.errmsg
														+ "</font></p></td></tr>");
										launchTestResult(key.find("td:last a")
												.get(0));
									} else if (data.data.result == "SKIP") {
										key
												.find("td:last")
												.html(
														"<font color=\"yellow\">SKIP</font>"
																+ "<a class=\"table-expandable-arrow btn btn-sm\" onclick=\"launchTestResult(this);\" style=\"margin:0 auto;margin-top: 5px;\"></a>");
										if (isContains(
												key.next().attr('class'),
												'tr-expandable')) {
											key.next().remove();
										}
										key
												.after("<tr style=\"display: none;overflow: hidden;\" class=\"tr-expandable\"><td colspan=\"10\"> <p><font size=\"2\">接口返回&nbsp;&nbsp;:&nbsp;&nbsp;</font>"
														+ data.data.returns
														+ "</p><p><font size=\"2\">错误详情&nbsp;&nbsp;:&nbsp;&nbsp;</font><font color=\"red\">"
														+ data.data.errmsg
														+ "</font></p></td></tr>");
										launchTestResult(key.find("td:last a")
												.get(0));
									}
								}
							});
				});
	}
}
function selectintertype() {
	var intertype = $("#intertype").find('option:selected').val();
	var intername = "";
	if (!isStrEmpt($("#interface").find('option:selected').val())) {
		intername = $("#interface").find('option:selected').text();
	}
	if (intertype == "DSP") {
		$("#hideouter").hide();
		$("#dsp_keyandsecret").show();
		$("#hidedata")
				.html(
						"<table id=\"param_tb\"  style=\"width: 100%\">"
								+ "<tr>"
								+ "<td style=\"width: 8%;float:left;\">"
								+ "<input class=\"form-control urlparam_key\" type=\"text\" value=\"app_key\">"
								+ "</td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\">:</td>"
								+ "<td style=\"width: 8%;float:left;\">"
								+ "<input id=\"param_appkey\" dragtype=\"paramsfuction\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\" class=\"form-control urlparam_value\" type=\"text\" value=\"bc7e94\">"
								+ "</td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\"><a onclick=\"deleteparam(this);\" href=\"####\"><img width=\"100%\" height=\"100%\" border=\"0\" src=\"img/delete.gif\"></a></td>"
								+ "<td align=\"center\" style=\"width: 2%;float:left;\">|</td>"
								+ "<td style=\"width: 8%;float:left;\"><input class=\"form-control urlparam_key\" type=\"text\" value=\"method\"></td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\">:</td>"
								+ "<td id=\"method_value\" style=\"width: 8%;float:left;\"><input dragtype=\"paramsfuction\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\" class=\"form-control urlparam_value\" type=\"text\" value=\""
								+ intername
								+ "\"></td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\"><a onclick=\"deleteparam(this);\" href=\"####\"><img width=\"100%\" height=\"100%\" border=\"0\" src=\"img/delete.gif\"></a></td>"
								+ "<td align=\"center\" style=\"width: 2%;float:left;\">|</td>"
								+ "<td style=\"width: 8%;float:left;\"><input class=\"form-control urlparam_key\" type=\"text\" value=\"timestamp\"></td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\">:</td>"
								+ "<td style=\"width: 8%;float:left;\"><input dragtype=\"paramsfuction\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\" class=\"form-control urlparam_value\" type=\"text\" value=\"now()\"></td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\"><a onclick=\"deleteparam(this);\" href=\"####\"><img width=\"100%\" height=\"100%\" border=\"0\" src=\"img/delete.gif\"></a></td>"
								+ "<td align=\"center\" style=\"width: 2%;float:left;\">|</td>"
								+ "<td style=\"width: 8%;float:left;\"><input class=\"form-control urlparam_key\" type=\"text\" value=\"sign\"></td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\">:</td>"
								+ "<td style=\"width: 8%;float:left;\"><input id=\"param_sign\" dragtype=\"paramsfuction\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\" class=\"form-control urlparam_value\" type=\"text\" value=\"sign2(appkey,method,format,timestamp,${jsonParams},88DA9E321AF1B146B758460D5D0697F8)\"></td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\"><a onclick=\"deleteparam(this);\" href=\"####\"><img width=\"100%\" height=\"100%\" border=\"0\" src=\"img/delete.gif\"></a></td>"
								+ "<td align=\"center\" style=\"width: 2%;float:left;\">|</td>"
								+ "<td style=\"width: 8%;float:left;\"><input class=\"form-control urlparam_key\" type=\"text\" value=\"format\"></td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\">:</td>"
								+ "<td style=\"width: 8%;float:left;\"><input dragtype=\"paramsfuction\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\" class=\"form-control urlparam_value\" type=\"text\" value=\"json\"></td>"
								+ "<td align=\"center\" style=\"width: 1%;float:left;\"><a onclick=\"deleteparam(this);\" href=\"####\"><img width=\"100%\" height=\"100%\" border=\"0\" src=\"img/delete.gif\"></a></td>"
								+ "</tr>" + "</table>");
		$("#hidedata").hide();
		$("#hiddeUrlToParam").hide();
	} else {
		$("#hideouter").show();
		$("#dsp_keyandsecret").hide();
		$("#hidedata").show();
		$("#hiddeUrlToParam").show();
	}
}

function showModules(element) {
	var env = $(element).find('option:selected').val();
	$.ajax({
		url : "/smarttest-frontstage/AutoInterface/getModuleByEnv.action",
		method : 'POST',
		data : {
			id : env
		},
		async : false,
		success : function(data) {
			if (data.status == 200 && data.data) {
				var html = "";
				for (var i = 0; i < data.data.length; i++) {
					var value = data.data[i];
					html += "<option value=\"" + value.id + "\" " + ">"
							+ value.name + "</option>";
				}
				$("#module").empty();
				$("#module").html(html);
			}
		}
	});
	showURL(element);
}

function loadSummById(id) {
	$.ajax({
		url : "/smarttest-frontstage/AutoInterface/loadSummById.action",
		data : {
			id : id,
		},
		method : 'POST',
		success : function(data) {
			if (data.status == 200 && data.data) {
				var value = data.data[0];
				$("#sumidHide").val(id);
				initEnvAndUrl(value.envid);
				$("#module").find("option[value='" + value.moduleid + "']")
						.attr("selected", true);
				$("#degree").find("option[value='" + value.degreeid + "']")
						.attr("selected", true);
				$("#tester").find("option[value='" + value.tester + "']").attr(
						"selected", true);
				$("#requestType").find(
						"option[value='" + value.requesttype + "']").attr(
						"selected", true);
				var outterParams = JSON.parse(value.outerparams);
				var appkey = outterParams['app_key'];
				$("#app_key").val(appkey);
				var sign = outterParams['sign'];
				var start = sign.lastIndexOf(',');
				var end = sign.length;
				var secret = sign.substring(start + 1, end - 1);
				$("#secret").val(secret);
				loadDetailBySummaryId(id);
				initInfSelectBox(value.name);
			}
		}
	});
}

function loadDetailBySummaryId(id) {
	$
			.ajax({
				url : "/smarttest-frontstage/AutoInterface/loadDetailBySummaryId.action",
				data : {
					id : id,
				},
				method : 'POST',
				success : function(data) {
					if (data.status == 200 && data.data) {
						for (var i = 0; i < data.data.length; i++) {
							var value = data.data[i];
							addrowWithDetailData(value);
						}
					}
				}
			});
}

function addrowWithDetailData(data) {
	$("#tbody")
			.append(
					"<tr><td align=\"center\"><input type=\"checkbox\" class=\"checkTestData\" onclick=\"javascript:singleCheckData(this);\" value="
							+ data.id
							+ "></td>"
							+ "<td dragtype=\"interparam\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\">"
							+ loadParamsFromData(data.innerparams)
							+ "</td>"
							+ "<td><input style=\"width:100%;\" type=\"text\" value="
							+ data.expectcode
							+ "></td>"
							+ "<td><input style=\"width:100%;\" type=\"text\" value="
							+ data.expectmsg
							+ "></td>"
							+ "<td dragtype=\"assertfuction\" ondrop=\"drop(event);\" ondragover=\"allowDrop2(event);\">"
							+ loadAssertsFromData(data.resultasserts)
							+ "</td>"
							+ "<td><input style=\"width:100%;\" type=\"text\" value="
							+ data.expectcount
							+ "></td>"
							+ "<td><div class=\"smart-form\" role=\"form\"><section class=\"pull-left no-padding col selectLevel\" style=\"width: 100%;\"><label class=\"select\" style=\"width: 100%;\"><select class=\"input-sm\" style=\"width: 100%;\"><option value=\"1\" selected=\"selected\">1</option><option value=\"2\">2</option></select><i></i></label></section></div></td>"
							+ "<td><input style=\"width:100%;\" type=\"text\" value="
							+ data.description
							+ "></td>"
							+ "<td align=\"center\"><input style=\"width:100%;\" type=\"button\" value=\"运行\" onclick=\"debugTest(getCurrentCase(this));\"></td>"
							+ "<td></td>" + "</tr>");
	var height = $("body").height();
	window.parent.document.getElementById("right_main").height = height;
}

function loadAssertsFromData(data) {
	var html = "";
	if (data == "") {
	} else {
		var assertsData = JSON.parse(data);
		for (key in assertsData) {
			var assertsRaw = assertsData[key];
			var start = assertsRaw.lastIndexOf('.');
			var end = assertsRaw.length;
			var asserts = assertsRaw.substring(start + 1, end);
			html += "<label onmousemove=\"mouseover(this);\" onmouseout=\"mouseout(this);\" style=\"margin-bottom:0px !important;\"><div style=\"float:left\"><a class=\"btn btn-info assert-details\" type=\"button\" classname=\"com.smarttest.portal.function.assertfuction.JsonCompare\" style=\"margin-left: 5px\">"
					+ asserts
					+ "</a></div><div style=\"float: left; width: 20px; height: 32px; display: none;\" class=\"delassert\"><a href=\"####\" onclick=\"deleteassert(this);\"><img width=\"15px\" height=\"15px\" border=\"0\" src=\"img/delete.gif\"></a></div></label>";
		}
	}
	return html;
}

function loadParamsFromData(data) {
	var html = "<table style=\"width: 100%\"><tbody>";
	if (data == "") {
	} else {
		var innerParams = JSON.parse(data);

		for (key in innerParams) {
			html += "<tr><td style=\"float:left;\"><a dragtype=\"interparam\" class=\"btn btn-success\" type=\"button\" draggable=\"true\" ondragstart=\"drag(event)\">"
					+ key
					+ "</a></td><td align=\"center\" style=\"float:left;\">:</td><td style=\"width: 100px;float:left;\"><input type=\"text\" dragtype=\"paramsfuction\" class=\"form-control\" value=\""
					+ innerParams[key]
					+ "\"></td><td style=\"width: 13px;float:left;\" align=\"center\"><a href=\"####\" onclick=\"deleteInterparam(this);\" classname=\"\"><img border=\"0\" src=\"img/delete.gif\" width=\"100%\" height=\"100%\"></a></td></tr>";
		}
		html += "</tbody></table>";
	}
	return html;
}
